﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Oracle.DataAccess.Client;

namespace Pension.DAL
{
    public class DbParameter
    {
        private OracleParameter[] dbParameters = null;

        public DbParameter()
        {

        }

        public void CreateParameters(int paramsCount)
        {
            dbParameters = new OracleParameter[paramsCount];
        }

        public void AddParameter(int index, string paramName, object objValue)
        {
            if (index < dbParameters.Length)
            {
                dbParameters[index] = new OracleParameter();
                dbParameters[index].ParameterName = paramName;
                dbParameters[index].Value = objValue;
            }
        }

        public void AddParameter(int index, string paramName, ParameterDirection paramDirect, ParameterType paramType)
        {
            if (index < dbParameters.Length)
            {
                dbParameters[index] = new OracleParameter();
                dbParameters[index].ParameterName = paramName;

                dbParameters[index].Direction = paramDirect;
                switch (paramType)
                {
                    case ParameterType.DbDateTime:
                        dbParameters[index].OracleDbType = OracleDbType.Date;
                        break;

                    case ParameterType.DbDecimal:
                        dbParameters[index].OracleDbType = OracleDbType.Decimal;
                        break;

                    case ParameterType.DbInt:
                        dbParameters[index].OracleDbType = OracleDbType.Int32;
                        break;

                    case ParameterType.DbString:
                        dbParameters[index].OracleDbType = OracleDbType.Varchar2;
                        dbParameters[index].Size = 1024;
                        break;

                    case ParameterType.DbTable:
                        dbParameters[index].OracleDbType = OracleDbType.RefCursor;
                        break;

                    default:
                        dbParameters[index].OracleDbType = OracleDbType.RefCursor;
                        break;
                }
            }
        }

        public OracleParameter[] Parameters
        {
            get
            {
                return dbParameters;
            }
        }
    }
}
